package com.azt.provider.impl;

import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.azt.api.pojo.Contract;
import com.azt.api.service.ContractService;
import com.azt.model.page.Pagination;
import com.azt.provider.mapper.ContractMapper;
import com.azt.utils.CommonUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

@Service
@Transactional
public class ContractServiceImpl implements ContractService {

	@Autowired
	private ContractMapper contractMapper;

	@Override
	public Pagination getContractPageBy(int pageno, int pagesize, Map<String, String> searchMap) {
		Integer companyid = CommonUtil.safeToInteger(searchMap.get("so_companyid"));

		Page<Object> startPage = PageHelper.startPage(pageno, pagesize);
		List<Contract> contractList = contractMapper.getContracts(companyid);

		Pagination p = new Pagination(startPage, contractList);
		p.setList(contractList);
		p.setParams(searchMap);
		return p;
	}

	@Override
	public void deleteAllById(Integer id) {
		contractMapper.deleteByPrimaryKey(id);
	}

	@Override
	public void saveContract(Contract contract) {
		contractMapper.insert(contract);
	}

	@Override
	public void saveEdit(Contract contract) {
		contractMapper.updateByPrimaryKey(contract);
	}

	@Override
	public Contract queryById(Integer id) {
		return contractMapper.selectById(id);
	}

}
